package display;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Hashtable;

import utility.*;
import java.util.Vector;



import database.RecordSearch;
import dbmanager.Column;
import dbmanager.DBManager;
import dbmanager.GetIdName;
import file.FileUtility;
//import file.SearchRecord;

public class Heading
{
	DBManager db = new DBManager();
	String id;
	String HEADING="Heading";
	GetIdName gid ;
	//String Basic_path=Input.MASTERREPORTSPATH;
	String path;
	//SearchRecord Sr;
	RecordSearch ps;
	Hashtable<Object, Object> table =new Hashtable<Object, Object>();
	public Vector<Field> Heading_vector= new Vector<Field>();
	public Heading(String id)
	{
	
		this.id = id;
		db.getConnect();
		gid = new GetIdName(db);
		HEADING = gid.getId(HEADING);
	//	path = Basic_path.concat(id+"//"+id+"_mid"+".txt");
		table.put("mid", id);
		table.put("pid", HEADING);
		table.put("td", "null");
		/*Sr = new SearchRecord(path);
		Sr.fileOpen();
		String line[] = Sr.getRecordSet(table);
		Sr.fileClose();*/
		
		ps = new RecordSearch(db);
		ps.setConditionMap(table);
		String line[] = ps.getArrayFromResultSet();
		for(int i=0;i<line.length;i++)
		{
			String splitline[]=line[i].split("\t");
			this.id = splitline[Column.pv_index-1]; 
		}
	//	path = Basic_path.concat(this.id+"//"+this.id+"_mid"+".txt");
	
	}

	public void get_Object()
	{	
		Hashtable<Object,Object> map = new Hashtable<Object,Object>();
		map.put("mid", id);
		map.put("td", "null");
		try {
			//RandomAccessFile file1 = new RandomAccessFile(path,"r");
			//FileUtility Fu =  new FileUtility(file1);
			/*Sr = new SearchRecord(path);
			System.out.println(map);
			String line[] = Sr.getRecordSet(map);*/
			
			ps = new RecordSearch(db);
			ps.setConditionMap(map);
			String line[] = ps.getArrayFromResultSet();
			//int index_pid =  Fu.getColumnIndex("pid")-1;			
			//int index_pv =   Fu.getColumnIndex("PV")-1;
			int index_pid =  Column.pid_index-1;			
			int index_pv = Column.pv_index-1;   
			for(int i=0;i<line.length;i++)
			{
				String SubString[] = line[i].split("\t");
				if(SubString[index_pid].equals(HEADING))
				{
					Field f = new Field();
					f.setId(SubString[index_pv], db);
					f.getObject();
					Heading_vector.add(f);
				}	
			}
			for(int i=0;i<Heading_vector.size();i++)
				System.out.println("The Vector is "+Heading_vector.get(i).Result);
			//file1.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static void main(String[] args) 
	{
		Heading hd = new Heading("7380");
		hd.get_Object();
	}
}